//
// Created by yyancy on 2020/4/18.
//
#include <iostream>
#include "cd.h"
#include <cstring>

//void Bravo(const Cd &disk);

void bravo(const Cd &disk) {
    disk.report();
}

Cd::Cd(const char *s1, const char *s2, int n, double x) {
//    size_t len = strlen(s1);
    strcpy(performers, s1);
    strcpy(label, s2);
    selections = n;
    playtime = x;
}

Cd::Cd(const Cd &d) {
    strcpy(performers, d.performers);
    strcpy(label, d.label);
    selections = d.selections;
    playtime = d.playtime;
}


void Cd::report() const {
    using std::cout;
    cout << "performers: " << performers
         << " label: " << label
         << " selections: " << selections
         << " palying time: " << playtime
         << std::endl;
}

Cd &Cd::operator=(const Cd &cd) {
    strcpy(performers, cd.performers);
    strcpy(label, cd.label);
    selections = cd.selections;
    playtime = cd.playtime;
    return *this;
}

int main() {
    using namespace std;

    Cd c1("Beatles", "Capitol", 14, 35.5);
    Classic c2 = Classic("Piano SSonata in B flat",
                         "Alfred Brendel", "Philips", 2, 57.17);

    Cd *pcd = &c1;

    cout << "Using object directly:\n";
    c1.report();
    c2.report();

    cout << "Using type cd * pointer to objects:\n";
    pcd->report();
    pcd = &c2;
    pcd->report();

    cout << "Calling a function with a Cd reference argument:\n";
    bravo(c1);
    bravo(c2);

    cout << "Testing assignment: \n";
    Classic copy2;
    copy2 = c2;
    copy2.report();

    return 0;

}

Classic::Classic(const char *s1, const char *s2, const char *s3, int i, double d)
        : Cd(s1, s2, i, d), name{0} {
    strcpy(name, s3);
}

Classic::Classic() : Cd(), name{0} {

}

void Classic::play() {
    std::cout << "233" << std::endl;
}

Classic &Classic::operator=(const Classic &d) {
    std::cout << "copy assignment function" << std::endl;
    Cd::operator=(d);
    strcpy(name, d.name);
    return *this;
}

void Classic::report() const {
    using std::cout;
    cout << "performers: " << performers
         << " label: " << label
         << " selections: " << selections
         << " palying time: " << playtime
         << " name: " << name
         << std::endl;
}

